package com.gilight.base.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gilight.base.dao.SysDictMapper;
import com.gilight.base.dto.SysDictDto;
import com.gilight.base.model.SysDict;
import com.gilight.base.service.ISysDictService;
import com.gilight.base.dto.DictModel;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 字典表 服务实现类
 * </p>
 *
 * @Author zhangweijian
 * @since 2018-12-28
 */
@Service
@Slf4j
public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> implements ISysDictService {

    @Autowired
    private SysDictMapper sysDictMapper;

    /**
     * 通过查询指定code 获取字典
     *
     * @param code
     * @return
     */
    @Override
    public List<DictModel> queryDictItemsByCode(String code) {
        log.info("无缓存dictCache的时候调用这里！");
        return sysDictMapper.queryDictItemsByCode(code);
    }

    @Override
    public List<DictModel> queryTableDictItemsByCode(String table, String text, String code) {
        log.info("无缓存dictTableList的时候调用这里！");
        return sysDictMapper.queryTableDictItemsByCode(table, text, code);
    }

    @Override
    public List<DictModel> queryTableDictItemsByCodeAndFilter(String table, String text, String code, String filterSql) {
        log.info("无缓存dictTableList的时候调用这里！");
        return sysDictMapper.queryTableDictItemsByCodeAndFilter(table, text, code, filterSql);
    }

    @Override
    public List<DictModel> queryAllDepartBackDictModel() {
        return baseMapper.queryAllDepartBackDictModel();
    }

    @Override
    public List<Map<String, Object>> selectByBzdm(String bzdm) {
        return sysDictMapper.selectByBzdm(bzdm);
    }

    @Override
    public PageInfo<SysDict> queryPageList(SysDictDto sysDictDto) {
        Integer pageNo = sysDictDto.getPageNo();
        Integer pageSize = sysDictDto.getPageSize();
        if (pageNo != null && pageSize != null) {
            PageHelper.startPage(pageNo, pageSize);
        }
        List<SysDict> sysDictList = sysDictMapper.queryPageList(sysDictDto);
        PageInfo<SysDict> sysDictPageInfo = new PageInfo<>(sysDictList);
        return sysDictPageInfo;
    }
}
